﻿using AdinZ.Common;
using Aliyun.OpenServices;
using Aliyun.OpenServices.OpenStorageService;
using Novel.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Xml;

namespace Novel.Test
{
    class Program
    {
        private static string accessId = "CQr3dtvHjRAEDchy";
        private static string accessKey = "oIW70rBElp2RtZCcIqao6LwwTVW4ru";
        static void Main(string[] args)
        {
            //HttpHelper http = new HttpHelper();
            //HttpItem item = new HttpItem()
            //{
            //    URL = "http://restapi.amap.com/log/init ",//URL     必需项    
            //    Method = "post",//URL     可选项 默认为Get   
            //    IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写   
            //    Cookie = "",//字符串Cookie     可选项   
            //    Referer = "",//来源URL     可选项   
            //    Postdata = "",//Post数据     可选项GET时不需要写   
            //    Timeout = 100000,//连接超时时间     可选项默认为100000    
            //    ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000   
            //    UserAgent = "AMAP Location SDK Android 1.1.0",//用户的浏览器类型，版本，操作系统     可选项有默认值   
            //    ContentType = "application/octet-stream",//返回类型    可选项有默认值   
            //    Allowautoredirect = false,//是否根据301跳转     可选项   
            //    //CerPath = "d:\123.cer",//证书绝对路径     可选项不需要证书时可以不写这个参数   
            //    //Connectionlimit = 1024,//最大连接数     可选项 默认为1024    
            //    ProxyIp = "",//代理服务器ID     可选项 不需要代理 时可以不设置这三个参数    
            //    //ProxyPwd = "123456",//代理服务器密码     可选项    
            //    //ProxyUserName = "administrator",//代理服务器账户名     可选项   
            //};
            //item.Header.Add("X-INFO", "H4sIAAAAAAAAAAF4AYf+lRCywYM/ANQZVuQPY7PVl7cRpQplag3RRVjUuUJ5DVxI2LDINcKBQY2rn+0KTwC1R3iDGjWnDj8rEIV0SIDTKWoGupKEGXHJTDDXl0fTD+S8a+O9WbQwKPyp8Q0Kxde4U2Amc8sdpLbExbU/vQm7vLxsTWVomqgIa9BluBA5repArU3bzPt+tNGwV6mynbyhUyT4sZA/oJ+UFv165O52GtMNPwHO4ovfomFCTDsojc+Y6MBLY7Kta4zeClaoZBiEXl6CX8fzjzAW9R4AYptL8O+xwJQNwPxjsXn1viROtQj5uuL8eBsyFJZIRMnBe7YMbgJYlDnzt+rpJDQgctupT4d/V0AwLQEAyGrj3NkYHWZ++yx5k/M5L+leGm3IGPaMsEa2AjqMCrfk3xuevFg8imv1N/xz92q902Zbry7keV/Hl3CQzlbkFa4ejOkX01IPr6D34UH7EDd0rrX4zgN91MJXZytptNVQuMeAnAgH+HGEl2zsXAolRPVrKgt4AQAA");
            //item.Header.Add("X-BIZ", "{\"ex\":\"bW9kPVNDSC1JNzM5JnN2PTQuMS4yJm50PW1vYmlsZSZucD1DaGluYSBUZWxlY29t\"}");
            //item.Header.Add("KEY", "42a5720e2e6910f4060acb835252d9c9");
            //HttpResult result = http.GetHtml(item);

            //string html = result.Html;
            //string cookie = result.Cookie;




          //string utf=  System.Web.HttpUtility.UrlEncode("discount=0.00&payment_type=1&subject=小说坊充值500阅读币&trade_no=2014052851359176&buyer_email=wyll365@vip.qq.com&gmt_create=2014-05-28 22:17:07&notify_type=trade_status_sync&quantity=1&out_trade_no=0528221702-1623-10000&seller_id=2088411610615416&notify_time=2014-05-28 22:17:07&body=(10000)充值5元,500阅读币&trade_status=TRADE_FINISHED&is_total_fee_adjust=N&total_fee=0.01&gmt_payment=2014-05-28 22:17:07&seller_email=1454269@qq.com&gmt_close=2014-05-28 22:17:07&price=0.01&buyer_id=2088302261798761&notify_id=5c2ade91ef3ae793e51bcdeb41f3596068&use_coupon=N&sign_type=RSA&sign=CWfovGRDdyFcQVloXsbafVsgjD++vb2yi2ATSu33e9FMF3I/UzFxsbASr/AjiNEdrKUOxGcr8wJwEYcDIPjRhYBGomvlAu3eE8PK9MNtC3zqqOberS3o3bPeF0NMobqCt1gs3FI8yvnoB1PqTCPFKp8gHy2aiYafXp0R/yRqiQg=", System.Text.Encoding.UTF8);
          //string str1 = "0528221702-1623-10000";

          //str1 = str1.Substring(str1.Length - 5, 5);

          //  string str="A";

          //  if (str != null &&str.Length > 3)
          //  {
          //      Console.WriteLine("true");
          //  }

           // Getlocation(23.026912917642004, 113.74580708824999);
          //string[] address=  AdinZ.Common.GPS.GetAddress(23.026912917642004, 113.74580708824999);



          //  Console.WriteLine(Distance(23.02643743, 113.74889437, 23.022241, 113.75441));

            SQL();
                Console.ReadKey();
        }


        /// <summary>
        ///计算两点GPS坐标的距离
        /// </summary>
        /// <param name="n1">第一点的纬度坐标</param>
        /// <param name="e1">第一点的经度坐标</param>
        /// <param name="n2">第二点的纬度坐标</param>
        /// <param name="e2">第二点的经度坐标</param>
        /// <returns></returns>
        public static double Distance(double n1, double e1, double n2, double e2)
        {
            double jl_jd = 102834.74258026089786013677476285;
            double jl_wd = 111712.69150641055729984301412873;
            double b = Math.Abs((e1 - e2) * jl_jd);
            double a = Math.Abs((n1 - n2) * jl_wd);
            return Math.Sqrt((a * a + b * b));

        }


        public static string GetAddress(double lat, double lng)
        {
            XmlDocument xml=new XmlDocument();
            string mapApiUrl = "http://api.map.baidu.com/geocoder?output=xml&location=" + lat + "," + lng + "&key=ACda8511540be1c8ba4a6b5933c832cd";
            string xmlSrc = AdinZ.Common.NetServer.Get(mapApiUrl, System.Text.Encoding.UTF8);
            xml.LoadXml(xmlSrc);
            string address = xml.SelectSingleNode("//result/formatted_address").InnerText;
            string province = xml.SelectSingleNode("//result/addressComponent/province").InnerText;
            string city = xml.SelectSingleNode("//result/addressComponent/city").InnerText;
            string district = xml.SelectSingleNode("//result/addressComponent/district").InnerText;

            return address;
        }

        private static void SQL()
        {
            StringBuilder sb = new StringBuilder();
            using (FileStream fs = new FileStream("phone.txt", FileMode.OpenOrCreate, FileAccess.Read))
            {
                using (StreamReader sr = new StreamReader(fs))
                {
                    string line = "";

                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] sp = line.Split('|');

                        string model = sp[2];
                        string sdk = sp[3];
                        string os = sp[4];
                        string kernel = sp[12];
                        string agent = "Dalvik/1.6.0 (Linux; U; Android " + os + "; " + model + " Build/JZO54K)";
                        string firm = sp[11];
                        string size = sp[5];
                        string cu = sp[7];
                        string vid = sp[9];
                        string pid = sp[10];

                        string sql = "INSERT INTO `phone` (`Model`, `SDK`, `OS`, `Kernel`, `UserAgent`, `firm`, `ScreenSize`, `sn`, `cu`, `vid`, `pid`) VALUES "+
                                                         "('" + model + "', '" +
                                                         sdk + "', '" + os + "', '" + 
                                                         kernel + "', '" + agent + "', '" + firm + "', '" + size + "', '', '" + cu + "', '" + vid + "', '" + pid + "')";
                        if (AdinZ.DB.MySqlHelper.NonQuery(sql) > 0)
                        {
                            Console.WriteLine("yes");

                        }
                        else
                        {
                            Console.WriteLine("No");
                        }
                        //Console.WriteLine(line);
                        Thread.Sleep(0);
                    }
                }
            }

        }



    }
}
